home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTValHashSetIterator<T,H,EQ> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include<rw/tvhset.h> RWTValHashSet<T,H,EQ> m; RWTValHashSetIterator<T,H,EQ> itr(m); PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!! IIIIffff yyyyoooouuuu hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd hhhheeeerrrreeee.... OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee rrrreeeessssttttrrrriiiicccctttteeeedddd iiiinnnntttteeeerrrrffffaaaacccceeee ttttoooo RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhTTTTaaaabbbblllleeeeIIIItttteeeerrrraaaattttoooorrrr described in Appendix A. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr is supplied with TTTToooooooollllssss....hhhh++++++++ 7 to provide an iterator interface to RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr that is backward compatible with the container iterators provided in TTTToooooooollllssss....hhhh++++++++ 6.x. Iteration over an RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeetttt is pseudorandom and dependent on the capacity of the underlying hash table and the hash function being used. The only useable relationship between consecutive elements is that elements which are defined to be equivalent by the equivalence object, EEEEQQQQ, will remain adjacent. The current item referenced by this iterator is undefined after construction or after a call to rrrreeeesssseeeetttt(((()))). The iterator becomes valid after being advanced with either a pre-increment or an ooooppppeeeerrrraaaattttoooorrrr(((()))). For both ooooppppeeeerrrraaaattttoooorrrr++++++++ and ooooppppeeeerrrraaaattttoooorrrr(((()))), iterating past the last element will return a value equivalent to boolean ffffaaaallllsssseeee. Continued increments will return a value equivalent to ffffaaaallllsssseeee until rrrreeeesssseeeetttt(((()))) is called. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee None EEEExxxxaaaammmmpppplllleeee #include<rw/tvhset.h> #include<rw/cstring.h> #include<iostream.h> struct silly_h{ PPPPaaaaggggeeee 1111 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) unsigned long operator()(const RWCString& x) const { return x.length() * (long)x(0); } }; int main(){ RWTValHashSet <RWCString, silly_h,equal_to<RWCString> > age; RWTValHashSetIterator <RWCString, silly_h, equal_to<RWCString > > itr(age); age.insert("John"); age.insert("Steve"); age.insert("Mark"); //Duplicate insertion rejected age.insert("Steve"); for(;itr();) cout << itr.key() << endl; return 0; } Program Output (not necessarily in this order) John Steve PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss Mark RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>> (RWTValHashSet<T,H,EQ>&h); Creates an iterator for the hashset hhhh. The iterator begins in an undefined state and must be advanced before the first element will be accessible. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss RWBoolean ooooppppeeeerrrraaaattttoooorrrr(((())))(); Advances sssseeeellllffff to the next element. Returns ffffaaaallllsssseeee if the iterator has advanced past the last item in the container and ttttrrrruuuueeee otherwise. RWBoolean ooooppppeeeerrrraaaattttoooorrrr++++++++(); Advances sssseeeellllffff to the next element. If the iterator has been reset or just created sssseeeellllffff will now reference the first element. If, before iteration, sssseeeellllffff referenced the last value in the multi-set, sssseeeellllffff will now reference an undefined value and ffffaaaallllsssseeee will be returned. Otherwise, ttttrrrruuuueeee PPPPaaaaggggeeee 2222 RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) is returned. Note: no postincrement operator is provided. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss RWTValHashSet<T,H,EQ>* ccccoooonnnnttttaaaaiiiinnnneeeerrrr(((()))) const; Returns a pointer to the collection being iterated over. T kkkkeeeeyyyy() const; Returns the value currently pointed to by sssseeeellllffff. void rrrreeeesssseeeetttt(); void rrrreeeesssseeeetttt(RWTValHashSet<T,H,EQ>& h); Resets the iterator so that after being advanced it will reference the first element of the collection. Using rrrreeeesssseeeetttt(((()))) with no argument will reset the iterator on the current container. Supplying a RRRRWWWWTTTTVVVVaaaallllHHHHaaaasssshhhhSSSSeeeetttt to rrrreeeesssseeeetttt(((()))) will reset the iterator on that container. PPPPaaaaggggeeee 3333